package com.jdls.day12.work;

/**
 * @author 嘉德罗斯
 * @date 2021/8/2
 */
public class Student  implements Comparable<Student>{
    //定义学生类，有姓名，年龄，分数三个属性。
    private String name;
    private int  age;
    private int  score;

    public Student() {
    }

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {

        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        int a = this.score - o.score;
        a = a==0? this.age - o.age:a;
        if(a == 0){
            for (int i = 0; i < this.name.length()||i<o.name.length(); i++) {
                if (this.name.charAt(i) + "" == null) {
                    return -1;
                } else {
                    a = this.name.charAt(i) - o.name.charAt(i);
                }
            }
        }
        return a;
    }
}
